import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { CampusService } from './campus.service';
import { CreateCampusDto, BaseCampusDto, UpdateCampusDto, QueryCampusDto, ListCampusDto } from './dto/campus.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from '../../system/user/user.decorator';
import { RepeatSubmit } from '../../../common/decorators/repeat-submit.decorator';
import {BusinessType} from "../../../common/constant/business.constant";
import {Operlog} from "../../../common/decorators/operlog.decorator";

@ApiTags('校区表')
@Controller('edutation/campus')
export class CampusController {
  constructor(private readonly campusService: CampusService) {}
  @ApiOperation({ summary: '校区表-创建' })
  @ApiDataResponse(BaseCampusDto)
  @RequirePermission('edutation:campus:add')
  @Post()
  @RepeatSubmit()
  @Operlog({ businessType: BusinessType.UPDATE })
  create(@Body() body: CreateCampusDto, @UserTool() { injectCreate }: UserToolType) {
    return this.campusService.create(injectCreate(body));
  }

  @ApiOperation({ summary: '校区表-列表' })
  @ApiDataResponse(ListCampusDto, true, true)
  @RequirePermission('edutation:campus:list')
  @Get('list')
  findAll(@Query() query: QueryCampusDto) {
    return this.campusService.findAll(query);
  }

  @ApiOperation({ summary: '校区表-详情' })
  @ApiDataResponse(BaseCampusDto)
  @RequirePermission('edutation:campus:query')
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.campusService.findOne(+id);
  }

  @ApiOperation({ summary: '校区表-修改' })
  @ApiDataResponse()
  @RequirePermission('edutation:campus:edit')
  @Put()
  @RepeatSubmit()
  @Operlog({ businessType: BusinessType.UPDATE })
  update(@Body() body: UpdateCampusDto, @UserTool() { injectUpdate }: UserToolType) {
    return this.campusService.update(injectUpdate(body));
  }

  @ApiOperation({ summary: '校区表-删除' })
  @ApiDataResponse()
  @RequirePermission('edutation:campus:remove')
  @Delete(':ids')
  @Operlog({ businessType: BusinessType.DELETE })
  remove(@Param('ids') ids: string) {
    const campusIds = ids.split(',').map((id) => +id);
    return this.campusService.remove(campusIds);
  }
}
